import request from '@/utils/request'
import { getToken } from '@/utils/auth'
import { param } from '@/utils/index'

/**
 * 获取招募员列表
 */
export function pagingRecruiterList(query) {
  return request({
    url: '/user/recruiter/paging',
    method: 'get',
    params: query
  })
}

/**
 * 招募员销售排名分页查询
 */
export function pagingRecruiterRanking(query) {
  return request({
    url: '/user/recruiter/pagingRecruiterRanking',
    method: 'get',
    params: query
  })
}

// 保存用户(新增或者修改)，传复杂对象，参数用data
export function saveRecruiter(recruiter) {
  return request({
    url: '/user/recruiter/save',
    method: 'post',
    data: recruiter
  })
}

/**
 * 修改状态
 */
export function changeStatusFlag(recruiterId, statusFlag) {
  if (!recruiterId) {
    return false
  }
  if (statusFlag == null) {
    return false
  }
  return request({
    url: '/user/recruiter/changeStatusFlag',
    method: 'post',
    params:
      { recruiterId: recruiterId,
        statusFlag: statusFlag
      }
  })
}

/**
 * 删除
 */
export function deleteRecruiter(recruiterId) {
  if (!recruiterId) {
    return false
  }
  return request({
    url: '/user/recruiter/delete',
    method: 'post',
    params: { recruiterId }
  })
}

/**
 * 批量修改状态
 */
export function batchUpStatusFlag(recruiterIds, statusFlag) {
  if (!recruiterIds) {
    return false
  }
  return request({
    url: '/user/recruiter/batchUpdateStatusFlag',
    method: 'post',
    data: {
      recruiterIds: recruiterIds,
      statusFlag: statusFlag
    }
  })
}

/**
 * 批量删除
 * @param recruiterIds
 */
export function batchDelete(recruiterIds) {
  if (!recruiterIds) {
    return false
  }
  return request({
    url: '/user/recruiter/batchDelete',
    method: 'post',
    data: {
      recruiterIds: recruiterIds
    }
  })
}

// 统计招募员数量
export function countRecruiter(data) {
  return request({
    url: '/user/recruiter/countRecruiter',
    method: 'get',
    params: data
  })
}

// 重置招募员密码
export function changePassword(data) {
  return request({
    url: '/user/recruiter/changePassword',
    method: 'get',
    params: data
  })
}

// 导出
export function exportRecruiterRanking(entity) {
  return process.env.BASE_API + '/user/recruiter/exportRecruiterRanking?' + param(entity) + '&accessToken=' + getToken()
}

/**
 * 招募员团长招募码 获取
 */
export function getCommanderCode(recruiterId) {
  return request({
    url: '/user/recruiter/getCommanderCode',
    method: 'get',
    params: { recruiterId: recruiterId }
  })
}

/**
 * 获取招募员H5链接二维码
 */
export function getRecruiterH5QRCode(versionType, enterpriseId) {
  return request({
    url: '/user/recruiter/getRecruiterH5QRCode',
    method: 'get',
    params: { versionType: versionType, enterpriseId: enterpriseId }
  })
}

/**
 * 获取招募员默认分销比例
 */
export function getDefaultDistributeRatio(enterpriseId) {
  return request({
    url: '/user/recruiter/getDefaultDistributeRatio',
    method: 'get',
    params: { enterpriseId }
  })
}

/**
 * 设置招募员默认分销比例
 */
export function setDefaultDistributeRatio(enterpriseId, defaultDistributeRatio) {
  return request({
    url: '/user/recruiter/setDefaultDistributeRatio',
    method: 'post',
    params: { enterpriseId, defaultDistributeRatio }
  })
}

/**
 * 招募员团长招募码 获取
 */
export function pagingRecruitRecord(params) {
  return request({
    url: '/user/recruiter/pagingRecruitRecord',
    method: 'get',
    params: params
  })
}
// 统计招募员根据申请状态分组
export function statStatRecruiter(query) {
  return request({
    url: '/user/recruiter/statRecruiterByApplyStatus',
    method: 'get',
    params: query
  })
}
//  批量通过/拒绝
export function updateBatchApplyStatus(params) {
  return request({
    url: '/user/recruiter/updateBatchApplyStatus',
    method: 'post',
    params: params
  })
}
